# 引入pymysql
import pymysql

class MysqlHelper(object):
    def __init__(self):
        self.conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='123456', database='py14', charset='utf8mb4')
        self.cursor = self.conn.cursor()

    def execute_insert_sql(self, insert_sql, data):
        # 之前只给了一个insert_sql就执行了
        # insert_sql, data
        self.cursor.execute(insert_sql, data)
        self.conn.commit()

    def __del__(self):
        self.cursor.close()
        self.conn.close()


if __name__ == '__main__':
    helper = MysqlHelper()
    insert_sql = 'INSERT INTO weibo_test(create_at, content) VALUES (%s, %s)'
    data = ('10-1', "aaa数据库aaa'aaa'")

    helper.execute_insert_sql(insert_sql, data)